/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package queenb.web.controller;

import java.util.List;
import queenb.net.entitybean.A000;
import queenb.net.entitybean.N750;
import queenb.net.entitybean.V300;
import queenb.web.store.A000Store;
import queenb.web.store.N750Store;
import queenb.web.store.V300Store;
import queenb.web.supplier.store.V220Store;
import queenb.web.util.SessionProvider;
import queenb.web.util.Util;

/**
 *
 * @author Nguyen Hung
 */
public class V300Controller extends QueenbController {

    private int pv300;
    private int fk100;
    private int fv200;
    private String vv301;
    private int vn302;
    private String vv303;
    private String vv304;
    private String vv305;
    private V300Store v300Store;
    private String messageform;
    private boolean flag;
    private int FN750;
    private List<A000> listA000;// city
    private int FA000;
    private String vn302Str;

    public V300Controller() {
        v300Store = new V300Store();
        Object objectId = getRequest().getParameter("id");
        if (objectId != null) {
            this.fk100 = Util.parseInt(objectId);
            System.out.println("-----------CONG TY---" + fk100);

        }
        Object actionObject = getRequest().getParameter("action");
        if (actionObject != null) {
            if (actionObject.equals("add")) {
                Object objectPK100i = getRequest().getParameter("id");
                if (objectPK100i != null) {
                    this.fk100 = Util.parseInt(objectPK100i);


                }
            } else if (actionObject.equals("countrycity")) {
                Object fk100Object = getRequest().getParameter("fk100");
                if (fk100Object != null) {
                    fk100 = Util.parseInt(fk100Object);

                }
                Object fk100Object2 = getRequest().getParameter("vv301");
                if (fk100Object2 != null) {
                    vv301 = fk100Object2.toString();

                }
                Object fk100Object3 = getRequest().getParameter("vv304");
                if (fk100Object3 != null) {
                    vv304 = fk100Object3.toString();

                }
                Object fk100Object4 = getRequest().getParameter("vv305");
                if (fk100Object4 != null) {
                    vv305 = fk100Object4.toString();

                }
                Object fv200Object = getRequest().getParameter("fv200");
                if (fv200Object != null) {
                    fv200 = Util.parseInt(fv200Object);

                }
                Object priceObject = getRequest().getParameter("price");
                if (priceObject != null) {
                    vn302 = Util.parseInt((priceObject));
                    System.out.println("-----------Cacs bieen ddeer luu---" + fk100 + fv200 + vn302);
                }
            } else if (actionObject.equals("getidCountry")) {
                Object fn750Object = getRequest().getParameter("fn750");
                Object fkObject = getRequest().getParameter("fk100");
                if (fn750Object != null) {
                    FN750 = Util.parseInt(fn750Object);
                    fk100 = Util.parseInt(fkObject);
                    listA000 = getListCityAll(FN750, fk100);
                    System.out.println("------------- BOOSSS" + listA000.size());
                }

            } else if (actionObject.equals("getidcity")) {
                Object fa000Object = getRequest().getParameter("fa000");
                if (fa000Object != null) {
                    FA000 = Util.parseInt(fa000Object);
                }
                Object fn750Object = getRequest().getParameter("fn750");
                if (fn750Object != null) {
                    FN750 = Util.parseInt(fn750Object);
                }
                Object fk100Object = getRequest().getParameter("fk100");
                if (fk100Object != null) {
                    fk100 = Util.parseInt(fk100Object);
                }
                Object vn302Object = getRequest().getParameter("vn302");
                if (vn302Object != null) {
                    vn302 = Util.parseInt(vn302Object);
                }
                Object fv200Object = getRequest().getParameter("fv200");
                if (fv200Object != null) {
                    fv200 = Util.parseInt(fv200Object);
                }

                Object fk100Object5 = getRequest().getParameter("vv301");
                if (fk100Object5 != null) {
                    vv301 = fk100Object5.toString();
                }
                Object vn302Object6 = getRequest().getParameter("vv304");
                if (vn302Object6 != null) {
                    vv304 = vn302Object6.toString();
                }
                Object fv200Object7 = getRequest().getParameter("vv305");
                if (fv200Object7 != null) {
                    vv305 = fv200Object7.toString();
                }
                updateV220(fk100, fv200, FA000, vn302, vv301, vv304, vv305);

                System.out.println("-----------Cacs bieen ddeer luu222222222222---" + fk100 + fv200 + vn302 + FA000 + vv301 + vv304 + vv305);

            } else if (actionObject.equals("edit")) {
                Object pv300Object = getRequest().getParameter("pv300");
                Object fk100Object = getRequest().getParameter("fk100");

                if (pv300Object != null) {
                    pv300 = Util.parseInt(pv300Object);
                    getDetailIDV300(pv300);
                }
                if (fk100Object != null) {
                    fk100 = Util.parseInt(fk100Object);
                }
            }
        }


    }

    public List<N750> getListCountAll() {
        N750Store n750Store = new N750Store();
        try {
            List<N750> listCombT075 = n750Store.findAllN750ForCombo(getLogin().getModule(), getLogin().getCompanyNo(), fk100, getLogin().getUserName());
            return listCombT075;
        } catch (Exception e) {
            return null;
        }
    }

    public List<A000> getListCityAll(int id, int fk100d) {
        A000Store store = new A000Store();
        try {
            List<A000> listS200 = store.findAllA000ForCombo(getLogin().getModule(), getLogin().getCompanyNo(), id, fk100d, getLogin().getUserName());
            return listS200;
        } catch (Exception e) {
            return null;
        }
    }

    public void updateV300() {
        try {
            if (!"".equals(vn302Str)) {
                vn302 = Integer.parseInt(vn302Str.replaceAll(",", "").trim());
            }
            System.out.println("--------" + pv300 + "," + getLogin().getModule() + "," + getLogin().getCompanyNo() + "," + getFk100() + "," + getFv200() + "," + vv301 + "," + Double.valueOf(vn302) + "," + vv303 + "," + vv304 + "," + vv305 + "," + getLogin().getUserName());
            int count = v300Store.updateV300(pv300, getLogin().getModule(), getLogin().getCompanyNo(), getFk100(), getFv200(), vv301, Double.valueOf(vn302), vv303, vv304, vv305, getLogin().getUserName());
            if (count > 0) {
                setMessageform(getResourceString("success"));
            } else {
                setMessageform(getResourceString("error"));
            }
        } catch (Exception e) {
        }
    }

    public void updateV220(int fk100i, int fv200i, int fa000i, int vn302i, String vv301i, String vv304i, String vv305i) {
        try {
            V220Store v220Store = new V220Store();
            System.out.println("--------" + 0 + "," + getLogin().getModule() + "," + getLogin().getCompanyNo() + "," + fk100i + "," + fa000i + "," + fv200i + "," + null + "," + null + "," + null + "," + 0 + "," + null + "," + null + "," + null + "," + Double.valueOf(vn302i) + "," + getLogin().getUserName());
            int count = v220Store.updateV220(0, getLogin().getModule(), getLogin().getCompanyNo(), fk100i, fa000i, fv200i, null, null, vv301i, 0, vv304i, vv305i, null, Integer.valueOf(vn302i), getLogin().getUserName());
            System.out.println("---AAOU-----" + count);
        } catch (Exception e) {
        }
    }

    public List<V300> getListV300All() {
        try {
               if(SessionProvider.getSessionMapValue("PN100HD")!=null){
                fk100 = Util.parseInt(SessionProvider.getSessionMapValue("PN100HD"));
            }
            System.out.println("----------Dich vuj-------" + fk100);
            List<V300> listV300 = v300Store.getListV300All(getLogin().getModule(), getLogin().getCompanyNo(), 0, 0, fk100, getLogin().getUserName());
            System.out.println("-----------------" + listV300.size() + listV300.get(0).getVv301());
            return listV300;
        } catch (Exception e) {
            return null;
        }
    }

    public void getDetailIDV300(int id) {
        try {
            List<V300> listV300 = getListV300All();
            if (listV300 != null || listV300.size() > 0) {
                for (int i = 0; i < listV300.size(); i++) {
                    if (listV300.get(i).getPv300() == id) {
                        vv301 = listV300.get(i).getVv301();
                        // vn302 = listV300.get(i).getVn302();
                        vv304 = listV300.get(i).getVv304();
                        vv305 = listV300.get(i).getVv305();
                        fv200 = listV300.get(i).getFv200();
                        double vn302db = Util.convertStringToDouble(String.valueOf(listV300.get(i).getVn302()));
                        vn302Str = Util.numberformater(vn302db, "##,###,###");
                        System.out.println("-------ln203---" + vn302Str);
                        break;
                    }
                }
            }
        } catch (Exception e) {
        }
    }

    /**
     * @return the pv300
     */
    public int getPv300() {
        return pv300;
    }

    /**
     * @param pv300 the pv300 to set
     */
    public void setPv300(int pv300) {
        this.pv300 = pv300;
    }

    /**
     * @return the vv301
     */
    public String getVv301() {
        return vv301;
    }

    /**
     * @param vv301 the vv301 to set
     */
    public void setVv301(String vv301) {
        this.vv301 = vv301;
    }

    /**
     * @return the vn302
     */
    public int getVn302() {
        return vn302;
    }

    /**
     * @param vn302 the vn302 to set
     */
    public void setVn302(int vn302) {
        this.vn302 = vn302;
    }

    /**
     * @return the vv303
     */
    public String getVv303() {
        return vv303;
    }

    /**
     * @param vv303 the vv303 to set
     */
    public void setVv303(String vv303) {
        this.vv303 = vv303;
    }

    /**
     * @return the vv304
     */
    public String getVv304() {
        return vv304;
    }

    /**
     * @param vv304 the vv304 to set
     */
    public void setVv304(String vv304) {
        this.vv304 = vv304;
    }

    /**
     * @return the vv305
     */
    public String getVv305() {
        return vv305;
    }

    /**
     * @param vv305 the vv305 to set
     */
    public void setVv305(String vv305) {
        this.vv305 = vv305;
    }

    /**
     * @return the messageform
     */
    public String getMessageform() {
        return messageform;
    }

    /**
     * @param messageform the messageform to set
     */
    public void setMessageform(String messageform) {
        this.messageform = messageform;
    }

    /**
     * @return the fk100
     */
    public int getFk100() {
         if(SessionProvider.getSessionMapValue("PN100HD")!=null){
                fk100 = Util.parseInt(SessionProvider.getSessionMapValue("PN100HD"));
            }
        return fk100;
    }

    /**
     * @param fk100 the fk100 to set
     */
    public void setFk100(int fk100) {
        this.fk100 = fk100;
    }

    /**
     * @return the fv200
     */
    public int getFv200() {
        return fv200;
    }

    /**
     * @param fv200 the fv200 to set
     */
    public void setFv200(int fv200) {
        this.fv200 = fv200;
    }

    /**
     * @return the flag
     */
    public boolean isFlag() {
        return flag;
    }

    /**
     * @param flag the flag to set
     */
    public void setFlag(boolean flag) {
        this.flag = flag;
    }

    /**
     * @return the FN750
     */
    public int getFN750() {
        return FN750;
    }

    /**
     * @param FN750 the FN750 to set
     */
    public void setFN750(int FN750) {
        this.FN750 = FN750;
    }

    /**
     * @return the FA000
     */
    public int getFA000() {
        return FA000;
    }

    /**
     * @param FA000 the FA000 to set
     */
    public void setFA000(int FA000) {
        this.FA000 = FA000;
    }

    /**
     * @return the listA000
     */
    public List<A000> getListA000() {
        return listA000;
    }

    /**
     * @param listA000 the listA000 to set
     */
    public void setListA000(List<A000> listA000) {
        this.listA000 = listA000;
    }

    /**
     * @return the vn302Str
     */
    public String getVn302Str() {
        return vn302Str;
    }

    /**
     * @param vn302Str the vn302Str to set
     */
    public void setVn302Str(String vn302Str) {
        this.vn302Str = vn302Str;
    }
}
